home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1860 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.9 KB

  1. Path: gidora.kralizec.net.au!root
  2. From: jon@zeta.org.au
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: locking
  5. Date: 13 Jan 1996 14:12:09 GMT
  6. Organization: Kralizec Dialup Internet Sydney, +61-2-837-1183 V.32bis
  7. Message-ID: <4d8ejp$phs@gidora.kralizec.net.au>
  8. References: <4d0j6r$1ri@daphne.ecmwf.int> <NITIN.96Jan10103013@more.eng.sun.com>
  9. Reply-To: jon@zeta.org.au
  10. NNTP-Posting-Host: dialup08.syd1.zeta.org.au
  11. X-Newsreader: IBM NewsReader/2 v1.2.5
  12.  
  13. In <NITIN.96Jan10103013@more.eng.sun.com>, nitin@more.eng.sun.com (Nitin More [CONTRACTOR]) writes:
  14. >In article <30F3E9C3.15FB7483@intellektik.informatik.th-darmstadt.de> Enno Sandner <enno@intellektik.informatik.th-darmstadt.de> writes:
  15. >
  16. >> From: Enno Sandner <enno@intellektik.informatik.th-darmstadt.de>
  17. >
  18. >[deleted]
  19. >
  20. >> > 
  21. >> > This seems to work, but the LockObject is only destroyed at the
  22. >> > end of the block, locking my object for too long.
  23. >> > 
  24. >> > main()
  25. >> > {
  26. >> > 
  27. >> >         SharedObject<foo> fooH("lock");
  28. >> > 
  29. >> >         ... the lock is not set
  30. >> > 
  31. >> >         fooH->bar();
  32. >> > 
  33. >> >         .. the lock is set until the end.
  34. >> > }
  35. >> > 
  36. >> > Anyone got an idea ?
  37. >> > 
  38. >> 
  39. >> I would say the temporary object should be destroyed directly after
  40. >> the invocation of 'bar'.
  41. >> As a workarround you can put the member-function call in brackets, e.g.
  42. >> 
  43. >>             { foo->bar(); }
  44. >> 
  45. >>     Enno
  46. >
  47. >You need to put the declaration of fooH also in the block as follows:
  48. >
  49. >    {
  50. >        SharedObject<foo> fooH("lock");
  51. >        fooH->bar();
  52. >    .. the lock is set until the end **OF THE BLOCK**
  53. >    }
  54.  
  55. >    .. fooH is destructed at the end of the block releasing the lock.
  56. >
  57.  
  58. No it isn't.
  59.  
  60. The temporary created by fooH-> is guaranteed to be deleted
  61. by the end of the block (ARM 12.2) but it can be deleted before
  62. that - whether it is or not is implementation dependent.
  63.  
  64. Refer to my articles in comp.lang.c++.moderated for my other comments
  65. about implementing locking in this way.
  66.  
  67. jon.
  68.